package com.xinyue.center.dao.redis;

import com.xinyue.dao.IRedisKeyConfig;
import com.xinyue.game.common.SystemContext;

import java.time.Duration;

public enum EnumRedisKey implements IRedisKeyConfig {
    Account("account", Duration.ofDays(7)),
    PlayerUUID("playerUUID", Duration.ofDays(365)),
    ;
    private String key;
    private Duration duration;

    EnumRedisKey(String key, Duration duration) {
        this.key = key;
        this.duration = duration;
    }

    @Override
    public String buildKey(String... args) {

        if (args != null) {
            StringBuilder keyBuilder = new StringBuilder();
            keyBuilder.append(SystemContext.getNamespace()).append("_");
            for (String arg : args) {
                keyBuilder.append(arg).append("_");
            }
            keyBuilder.append(this.key);
            return keyBuilder.toString();
        }
        return this.key;
    }

    @Override
    public Duration getExpire() {
        return duration;
    }

}
